package com.example.trader.controller;


import com.example.trader.common.Result;
import com.example.trader.entity.MerchantPersonalInfo;
import com.example.trader.entity.TraderLogin;
import com.example.trader.service.TraderService;
import com.example.user.entity.UserLogin;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/trader")
@CrossOrigin(origins = "http://localhost:8080")
public class TraderController {

    @Autowired
    private TraderService traderService;

    @GetMapping("/getTraderInfo")
    public Result<PageInfo> getTraderInfo() {
        PageHelper.startPage(1,10);
       List<MerchantPersonalInfo> traderInfoList= traderService.getTraderInfo();
       return Result.success(new PageInfo(traderInfoList));
    }

    /**
     * 修改信息接口
     */
    @PutMapping("/updateTraderInfo")
    public Result updateTraderInfo(@RequestBody MerchantPersonalInfo traderInfo) {

        Result result=traderService.updateTraderInfo(traderInfo);
        return result;


    }




    /**
     * 登录接口
     */


    @PostMapping("/login")
    public Result login(@RequestBody TraderLogin traderLogin) {

       Result result= traderService.login(traderLogin);
       return result;
    }

    /**
     * 注册接口
     */
    @PostMapping("/register")
    public Result register(@RequestBody TraderLogin traderLogin)
    {
       Result resul =traderService.register(traderLogin);
       return resul;
    }






}
